package com.dsg.controller.oil;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsg.common.constants.MessageConstants;
import com.dsg.common.dto.AjaxResult;
import com.dsg.common.util.SingletonLoginUtils;
import com.dsg.common.util.toolbox.StringUtil;
import com.dsg.controller.base.BaseController;
import com.dsg.entity.oil.DsgOilDoubtList;
import com.dsg.service.oil.IDsgOilDoubtListService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 存疑记录 前端控制器
 * </p>
 *
 * @author system
 * @since 2020-07-31
 */
@RestController
@RequestMapping("/oil/dsgOilDoubtList")
public class DsgOilDoubtListController extends BaseController {

    @Autowired
    private IDsgOilDoubtListService service;

    /**
     * 查询列表（分页）
     *
     * @param dsgOilDoubtList
     * @return
     */
    @GetMapping(value = "/list")
    @ApiOperation("查询列表（分页）")
    public AjaxResult list(DsgOilDoubtList dsgOilDoubtList) {
        // 分页
        Page page = getPage();
        String sort = getParameter("sort");
        List<OrderItem> orderItemList = new ArrayList<>();
        OrderItem orderItem = new OrderItem();
        if (StringUtil.isEmpty(sort)) {
            orderItem.setColumn("d.PAY_ACCOUNT_NO");
            orderItem.setAsc(false);
            orderItemList.add(orderItem);
            page.setOrders(orderItemList);
        }
        dsgOilDoubtList.setEntCode(SingletonLoginUtils.getSystemEntCode());
        page = service.selectByList(page, dsgOilDoubtList);
//        List<DsgOilDoubtList> dsgOilDoubtListList = page.getRecords();
//        Map<String, List<DsgOilDoubtList>> dsgOilDoubtListMap = new HashMap<>();
//        if (CollectionUtil.isNotEmpty(dsgOilDoubtListList)) {
//            dsgOilDoubtListMap = dsgOilDoubtListList.stream().collect(Collectors.groupingBy(I -> I.getPayAccountNo()));
//        }
        // 格式要返回的数据
        AjaxResult ajaxResult = json(MessageConstants.SSO_STATUS_SUCCESS, page.getRecords(), (int) page.getTotal());
        return ajaxResult;
    }

}
